/*
 *  Main.java 
 * 
 *  Copyright (C) - 2008 - Juanbc - Aleval
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.bts.translateTool;

import com.bts.util.DMesg;
import com.bts.translateTool.view.TranslateJPanel;
import javax.swing.JFrame;

/**
 * Lanza la aplicacíon
 * @author juan
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        preProccess(args);
        setLookAndFeel();
        launchView();
    }
    
    /**
     * Genera la ventana para lanzar la aplicación
     */
    private static void launchView(){
        JFrame jframe=new JFrame();
        TranslateJPanel panel= new TranslateJPanel(null, TranslateJPanel.EXIT_ON_CLOSE, jframe);
        jframe.add(panel);
        jframe.setTitle(Info.PROGRAM_NAME + " - " + Info.VERSION);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        jframe.setBounds((screenSize.width-735)/2, (screenSize.height-469)/2, 735, 469);
        jframe.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jframe.setVisible(true);
    }
    
    /**
     * Preprocesa los parametros enviados por consola
     * @param args
     */
    private static void preProccess(final String[] args) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].toLowerCase().compareTo("-d") == 0) {
                DMesg.setOut(true);
            }
        }
    }
    
    /**
     * Setea el lookandfeel   de la aplicación para que se adapte al sistema
     */
    private static void setLookAndFeel() {
        try {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            String error = "Failure in charge system Look and Feel";
            DMesg.err(e, error);
            javax.swing.JOptionPane.showMessageDialog(null, error, "ERROR", javax.swing.JOptionPane.ERROR_MESSAGE);
        }
    }
}
